-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Deprecate inplace in Categorical.remove_categories #37981
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -352,7 +352,9 @@ def test_validate_inplace_raises(self, value): | |||
cat.add_categories(new_categories=["D", "E", "F"], inplace=value) | |||
|
|||
with pytest.raises(ValueError, match=msg): | |||
cat.remove_categories(removals=["D", "E", "F"], inplace=value) | |||
with tm.assert_produces_warning(FutureWarning): | |||
# issue #37643 inplace kwarg deprecated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I'd drop this comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yah i find these helpful
doc/source/whatsnew/v1.2.0.rst
Outdated
@@ -478,6 +478,7 @@ Deprecations | |||
- Partial slicing on unordered :class:`DatetimeIndex` with keys, which are not in Index is deprecated and will be removed in a future version (:issue:`18531`) | |||
- Deprecated :meth:`Index.asi8` for :class:`Index` subclasses other than :class:`DatetimeIndex`, :class:`TimedeltaIndex`, and :class:`PeriodIndex` (:issue:`37877`) | |||
- The ``inplace`` parameter of :meth:`Categorical.remove_unused_categories` is deprecated and will be removed in a future version (:issue:`37643`) | |||
- The ``inplace`` parameter of :meth:`Categorical.remove_categories` is deprecated and will be removed in a future version (:issue:`37643`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could merge with the entry for Categorical.remove_unused_categories
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
@@ -348,7 +348,10 @@ def test_remove_categories(self): | |||
tm.assert_categorical_equal(res, new) | |||
|
|||
# inplace == True | |||
res = cat.remove_categories("c", inplace=True) | |||
with tm.assert_produces_warning(FutureWarning): | |||
# issue #37643 inplace kwarg deprecated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and this one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
ok let's resolve the discussion on the issue first here. |
@arw2019 I fixed the 'whatsnew' entry as you asked. Updated to the latest master and resolved, hopefully all, unit test problems. |
This pull request is stale because it has been open for thirty days with no activity. Please update or respond to this comment if you're still interested in working on this. |
cat.remove_categories(replace_value, inplace=True) | ||
with catch_warnings(): | ||
simplefilter("ignore") | ||
cat.remove_categories(replace_value, inplace=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think eventually we'll need to push this up and deprecate inplace here in Categorical.replace, but that can be done in a separate step
needs rebase, otherwise LGTM |
@jbrockmendel |
pandas/core/arrays/categorical.py
Outdated
warn( | ||
"The `inplace` parameter in pandas.Categorical." | ||
"remove_categories is deprecated and " | ||
"will be removed in a future version.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
usually we would say "do X instead", but since the idea is to never change the dtype inplace, might be worth adding a short sentence like "Removing unused categories will always return a new Categorical object"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I updated the warning message.
pandas/core/arrays/categorical.py
Outdated
@@ -1140,6 +1144,8 @@ def remove_categories(self, removals, inplace=False): | |||
Whether or not to remove the categories inplace or return a copy of | |||
this categorical with removed categories. | |||
|
|||
.. deprecated:: 1.2.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1.3.0 now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch, thanks. I updated the version here and fixed conflicts with the master
one comment, otherwise looks ready |
thanks @OlehKSS let's merge on green. |
thanks @OlehKSS |
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff